package org.domain.sigepac.repository.impl;

import java.util.Collections;
import java.util.List;

import org.domain.sigepac.Entity.Turma;
import org.domain.sigepac.repository.RepositorioGenerico;
import org.domain.sigepac.repository.RepositorioTurma;
import org.hibernate.criterion.Order;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;



/**
 * @author bruno.canto
 */
@Name("repositorioTurma")
@AutoCreate
public class RepositorioTurmaImpl extends RepositorioGenerico<Turma>
    implements RepositorioTurma {


	@SuppressWarnings("unchecked")
	public List<Turma> pesquisarPorNome(String nome) {
		try {
			return (List<Turma>) this.entityManager.createQuery(
					"from Turma as turma where upper(turma.nome) like ?")
					.setParameter(1,"%"+nome.toUpperCase()+"%").getResultList();

		} catch (Exception e) {
			return Collections.EMPTY_LIST;
		}
	}

	@Override
	public List<Turma> listar() {

		return listarPorAtributo("ativo", true,Order.asc("nome"));
	}

	public List<Turma> listarInativas() {
		return listarPorAtributo("ativo", false);
	}

}
